package com.rykj.energy.basic.rest;

import com.rykj.energy.common.utils.Result;
import com.rykj.energy.database.pojo.BasicDataDictAttr;
import com.rykj.energy.database.service.IDataDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "字典")
@RestController
@RequestMapping("/dict")
public class DictController {

    @Resource
    private IDataDictService dataDictService;

    @ApiOperation("根据编号获取所有字典")
    @ApiImplicitParam(name = "dictNum",value = "字典编号",required = true,paramType = "path")
    @GetMapping("/findAll/{dictNum}")
    public Result<List<BasicDataDictAttr>> getInfo(@PathVariable("dictNum")String dictNum){
        return Result.success(dataDictService.findAllByDictNum(dictNum));
    }

    @ApiOperation("获取所有字典")
    @GetMapping("/findAll")
    public Result<List<BasicDataDictAttr>> findAll(){
        return Result.success(dataDictService.findAllDict());
    }


    @ApiOperation("查询基础字典信息")
    @GetMapping("/findBaseInfo")
    public Result findBaseInfo(){
        return Result.success(dataDictService.findBaseInfo());
    }

    @ApiOperation("修改基础字典信息")
    @PostMapping("/updateDataDictAttr")
    public Result updateDataDictAttr(@RequestBody BasicDataDictAttr dataDictAttr){
        dataDictService.updateDataDictAttr(dataDictAttr);
        return Result.success("修改成功",null);
    }
}
